﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SipII;
using SipII.Message;
using SipII.Parameter;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(TestPatronInformation());
            Console.WriteLine(TestCheckIn());
            Console.WriteLine(TestPatronInformation());
            Console.WriteLine(TestCheckOut());
            Console.WriteLine(TestPatronInformation());
            Console.ReadLine();
        }

        static string TestPatronInformation()
        {
            PatronInformation request = new PatronInformation();

            request.Language = GetEnumCode(enumLanguage.Chinese).ToCharArray();
            request.TransactionDate = GetDateCharArray();
            request.Summary = "          ".ToCharArray();
            request.InstitutionId = "931";
            request.PatronIdentifier = "931000003083";
            request.TerminalPassword = "sc001pass!@#";

            string response = Sip2ServerProxy.Response("001", request.ToString());

            return response;
        }

        static string TestCheckOut()
        {
            Checkout request = new Checkout();

            request.SCRenewalPolicy = 'N';
            request.NoBlock = 'Y';
            request.TransactionDate = GetDateCharArray();
            request.NbDueDate = GetDateCharArray();
            request.InstitutionId = "931";
            request.PatronIdentifier = "931000003083";
            request.ItemIdentifier = "200000024   ";
            request.TerminalPassword = "sc001pass!@#";

            string response = Sip2ServerProxy.Response("001", request.ToString());

            return response;

        }

        static string TestCheckIn()
        {
            Checkin request = new Checkin();

            request.NoBlock = 'N';
            request.TransactionDate = GetDateCharArray();
            request.ReturnDate = GetDateCharArray();
            request.CurrentLocation = "001";
            request.InstitutionId = "931";
            request.ItemIdentifier = "200000024   ";
            request.TerminalPassword = "sc001pass!@#";

            string response = Sip2ServerProxy.Response("001", request.ToString());

            return response;
        }

        static string GetEnumCode(object enumValue)
        {
            string typename = enumValue.GetType().Name;
            int length = Sip2Parameter.dicEnumCodeLength[typename];
            return ((int)enumValue).ToString("D" + length.ToString());
        }

        /// <summary>
        /// 返回YYYYMMDDZZZZHHMMSS格式的时间字符数组
        /// </summary>
        /// <returns></returns>
        static char[] GetDateCharArray()
        {
            return string.Format("{0}    {1}", DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss")).ToCharArray();
        }

        static char[] GetDateCharArray(DateTime dt)
        {
            return string.Format("{0}    {1}", dt.ToString("yyyyMMdd"), dt.ToString("HHmmss")).ToCharArray();
        }
    }
}
